﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using log4net;
namespace LuceneNetServices.QuzrtzNetCommon
{
    public class CustomJobListener : IJobListener
    {
        ILog log = LogManager.GetLogger(typeof(CustomJobListener));
        public virtual string Name
        {
            get
            {
                return "CustomJobListener";
            }
        }



        public void JobExecutionVetoed(IJobExecutionContext context)
        {
            string m_strJobName = context.JobDetail.Key.Name;
            log.Info("报表监视器：" + m_strJobName + "已经执行完毕" + DateTime.Now.ToString());
        }

        public void JobToBeExecuted(IJobExecutionContext context)
        {
            string m_strJobName = context.JobDetail.Key.Name;
            log.Info("报表监视器：" + m_strJobName + "将要实行" + DateTime.Now.ToString());
        }

        public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            string m_strJobName = context.JobDetail.Key.Name;
            log.Info("报表监视器：" + m_strJobName + "正在执行" + DateTime.Now.ToString());
            try
            {
                if (jobException != null)
                {
                    log.Info(jobException.Message);
                    jobException.RefireImmediately = true;
                    if (context.RefireCount != Models.LogCfg.RefireCount) return;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
            }


        }
    }
}
